#pragma once
#include <iostream>
#include <pthread.h>
class Mutex
{
public:
    Mutex(pthread_mutex_t* mutex):mutex_(mutex)
    {
        pthread_mutex_init(mutex_, nullptr);
    }
    ~Mutex()
    {
        pthread_mutex_destroy(mutex_);
    }
    void lock()
    {
        pthread_mutex_lock(mutex_);
    }
    void unlock()
    {
        pthread_mutex_unlock(mutex_);
    }

private:
    pthread_mutex_t* mutex_;
};
// RAII
class LockGuard
{
public:
    LockGuard(Mutex* mut) : _mut(mut)
    {
        _mut->lock();
    }
    ~LockGuard()
    {
        _mut->unlock();
    }

private:
    Mutex* _mut;
};